home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2005 February / PCpro_2005_02.ISO / files / opensource / jEdit_4.2 / jedit42install.exe / {app} / jedit.jar / bsh / CommandLineReader.class (.txt) < prev    next >
Encoding:
Java Class File  |  2004-08-29  |  1.3 KB  |  60 lines

  1. package bsh;
  2.  
  3. import java.io.FilterReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. import java.io.Reader;
  7.  
  8. class CommandLineReader extends FilterReader {
  9.    static final int normal = 0;
  10.    static final int lastCharNL = 1;
  11.    static final int sentSemi = 2;
  12.    int state = 1;
  13.  
  14.    public CommandLineReader(Reader in) {
  15.       super(in);
  16.    }
  17.  
  18.    public int read() throws IOException {
  19.       if (this.state == 2) {
  20.          this.state = 1;
  21.          return 10;
  22.       } else {
  23.          int b;
  24.          while((b = this.in.read()) == 13) {
  25.          }
  26.  
  27.          if (b == 10) {
  28.             if (this.state == 1) {
  29.                b = 59;
  30.                this.state = 2;
  31.             } else {
  32.                this.state = 1;
  33.             }
  34.          } else {
  35.             this.state = 0;
  36.          }
  37.  
  38.          return b;
  39.       }
  40.    }
  41.  
  42.    public int read(char[] buff, int off, int len) throws IOException {
  43.       int b = this.read();
  44.       if (b == -1) {
  45.          return -1;
  46.       } else {
  47.          buff[off] = (char)b;
  48.          return 1;
  49.       }
  50.    }
  51.  
  52.    public static void main(String[] args) throws Exception {
  53.       Reader in = new CommandLineReader(new InputStreamReader(System.in));
  54.  
  55.       while(true) {
  56.          System.out.println(in.read());
  57.       }
  58.    }
  59. }
  60.